const { defineConfig } = require("@vue/cli-service");
const path = require("path");

const resolve = (dir) => {
    return path.join(__dirname, dir);
};
const isProduction = process.env.NODE_ENV == "production";
// https://cli.vuejs.org/zh/config/#%E5%85%A8%E5%B1%80-cli-%E9%85%8D%E7%BD%AE
module.exports = defineConfig({
    transpileDependencies: true,
    publicPath: "./",
    filenameHashing: isProduction,
    productionSourceMap: true, // 打包时不生成.map文件
    configureWebpack: (config) => {},
    chainWebpack: (config) => {
        // 定义别名
        config.resolve.alias
            .set("@", resolve("src")) // key,value自行定义，比如.set('@@', resolve('src/components'))
            .set("_root", resolve("/"));

        // 这段是加载scss的全局变量，注意要 pnpm install sass-resources-loader -D
        // const oneOfsMap = config.module.rule("scss").oneOfs.store;
        // oneOfsMap.forEach((item) => {
        //     item.use("sass-resources-loader")
        //         .loader("sass-resources-loader")
        //         .options({
        //             // Provide path to the file with resources
        //             //resources: "./src/styles/variables.scss"

        //             // Or array of paths
        //             resources: ["./src/styles/variables.scss", "./src/styles/mixin.scss"],
        //         })
        //         .end();
        // });
    },
    devServer: {
        //allowedHosts: true,
        host: "127.0.0.1",
        open: true, // npm run serve 后会不会自动打开浏览器
        proxy: {
            "/apis/*": {
                target: "http://localhost:5005/", // 接口域名
                ws: true,
                pathRewrite: {
                    "^/apis": "",
                },
                changeOrigin: true, // 是否跨域
            },
            // "/res/*": {
            //     target: "http://localhost:5000/", // 接口域名
            //     ws: true,
            //     pathRewrite: {
            //         "^/res/": "/"
            //     },
            //     changeOrigin: true // 是否跨域
            // }
        },
    },
});
